package com.unbook.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.unbook.entity.AdminUser;
import com.unbook.entity.params.AdminLoginParam;
import com.unbook.mapper.IAdminUserMapper;
import com.unbook.service.IAdminUserService;
import com.unbook.service.IVerifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminUserServiceImpl extends ServiceImpl<IAdminUserMapper, AdminUser> implements IAdminUserService {
    private IVerifyService verifyService;
    @Autowired
    private IAdminUserMapper adminUserMapper;
    @Override
    public AdminUser login(AdminLoginParam param){
        AdminUser user = AdminUser.builder()
            .account(param.getAccount())
            .password(param.getPassword())
            .build();
        QueryWrapper<AdminUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("account", user.getAccount());
        queryWrapper.eq("password", user.getPassword());
        List<AdminUser> users = adminUserMapper.selectList(queryWrapper);
        if(users.size() > 0){
            return users.get(0);
        }
        return null;
    }
}
